// pages/add/add.js
const app = getApp()
const citys = require('../../utils/city.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBar_height: 0,
    avatarUrl: '../img/default_avatr.png',
    coverUrl:'../img/upload-cover.png',
    region: [Object.keys(citys), citys[Object.keys(citys)[0]]],
    select: ["", ""],
    city: '',
    cityList: [],
    citylastIndex: -1,
    videoUrl:'../img/upload_video.png'
  },

  //头像
  avatar:function(e){
    var that = this
    wx.chooseImage({
      count: 1,
      success: function(res) {
        that.setData({
          avatarUrl: res.tempFilePaths
        })

        wx.uploadFile({
            url: 'http://www.qiyuchuhai/xcx/comm/uploadFile',
          filePath: res.tempFilePaths[0],
          name: 'file',
          formData: {},
          success(res) {
            const data = res.data
            //do something
          }
        })
      },
    })
  },
 
//  上传封面
  cover: function (e) {
    var that = this
    wx.chooseImage({
      count: 1,
      success: function (res) {
        that.setData({
          coverUrl: res.tempFilePaths
        })

        wx.uploadFile({
            url: 'http://www.qiyuchuhai/xcx/comm/uploadFile',
          filePath: res.tempFilePaths[0],
          name: 'file',
          formData: {},
          success(res) {
            const data = res.data
            //do something
          }
        })
      },
    })
  },
  // 上传视频
  videos:function(e){
    console.log(1)
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: 'back',
      success(res) {
        this.setData({videoUrl:res.tempFilePath
        
        })
      
        console.log(res.tempFilePath)
      }
    })
  },
 


  bindChange: function (e) {
    if (!e.detail.value || e.detail.value.length < 2) return;
    var region = this.data.region;
    var pro_index = e.detail.value[0];
    var city_index = e.detail.value[1];
    this.setData({

      city: region[1][city_index]
    })

    console.log(region[1][city_index])
  },

  bindColumnChange: function (e) {

    if (e.detail.column === 0) {
      var region = this.data.region;
      var province = region[0][e.detail.value];
      console.log(region[0])
      this.setData({
        region: [region[0], citys[province]]
      });
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusBar_height: app.globalData.statubar_height
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})